package com.example.myweb.Controller.Auth;

import com.example.myweb.Common.ApiResponse;
import com.example.myweb.Domain.Entity.User;

import com.example.myweb.Dto.FollowRequestDTO;
import com.example.myweb.Dto.FollowUserInfoDTO;
import com.example.myweb.Exception.CustomException;
import com.example.myweb.Repository.JpaRepository.UserRepository;
import com.example.myweb.Service.Auth.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/follows")
public class FollowController {

    @Autowired
    private FollowService followService;

    @Autowired
    private UserRepository userRepository;

    /**
     * 关注一个用户
     * POST /follows
     */
    @PostMapping
    public ResponseEntity<ApiResponse<Void>> follow(
            @Valid @RequestBody FollowRequestDTO request,
            @AuthenticationPrincipal User currentUser) {

        followService.followUser(currentUser, request.getFollowedUserId());
        return ResponseEntity.ok(ApiResponse.success("关注成功"));
    }

    /**
     * 取消关注一个用户
     * DELETE /follows/{followedUserId}
     */
    @DeleteMapping("/{followedUserId}")
    public ResponseEntity<ApiResponse<Void>> unfollow(
            @PathVariable Long followedUserId,
            @AuthenticationPrincipal User currentUser) {

        followService.unfollowUser(currentUser, followedUserId);
        return ResponseEntity.ok(ApiResponse.success("取消关注成功"));
    }


}